package com.lcc.lynx.base.system.controller;

import com.lcc.lynx.common.ResultVO;
import com.lcc.lynx.jdbc.IByIdController;
import com.lcc.lynx.security.annotation.Permission;
import com.lcc.lynx.base.system.pojo.dv.SysMenuDV;
import com.lcc.lynx.base.system.service.SysMenuService;
import com.lcc.lynx.common.utils.StrUtil;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 系统菜单控制实现
 * @auth lcc
 * @date 2025-01-01
 */
@RestController
@AllArgsConstructor
@RequestMapping("/sys/menu")
public class SysMenuController implements IByIdController<SysMenuDV> {

    private SysMenuService service;
    

    @Override
    public SysMenuService getService() {
       return service;
    }

    @Override
    public ResultVO<SysMenuDV> insert(SysMenuDV dto) {
        service.insertAndPermission(dto);
        return ResultVO.success(dto);
    }

    @Override
    public ResultVO<?> delete(String idList) {
        if(StrUtil.isEmpty(idList)){
            return ResultVO.fail("idList不能为空");
        }
        List<Long> list = new ArrayList<>();
        Arrays.stream(idList.split(",")).forEach(s -> list.add(Long.valueOf(s)));
        service.deleteAndChildren(list);
        return ResultVO.success();
    }

    @RequestMapping("/sort")
    @Permission(Permission.upd)
    public ResultVO<?> sort(@RequestBody List<SysMenuDV> list){
        service.sort(list);
        return ResultVO.success();
    }
}